﻿Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data

Public Class GlobalFunctions
    Function OpenNewWindow(ByVal Link As String) As String
        Dim TheLink As String
        'function RedirectToNewWindow(){
        TheLink = "<script> newwindow=window.open ('"
        TheLink = TheLink + Link
        TheLink = TheLink + "', '_blank','menubar=yes,resizable=yes,scrollbars=yes,status=yes');"
        TheLink = TheLink + "</script>"
        'return true;}
        Return TheLink
    End Function

    Public Function FormatDBDate(ByVal myDateTime As String) As String

        Dim dateTimeArray As String() = myDateTime.Split(" ")

        Dim dateArray As String()

        If (dateTimeArray(0).ToString().Contains(":") = True) Then
            dateArray = dateTimeArray(1).Split("/")
        Else
            dateArray = dateTimeArray(0).Split("/")
        End If



        Dim nDay As Integer = dateArray(0)
        Dim nMonth As Integer = dateArray(1)
        Dim nYear As Integer = dateArray(2)

        Dim timeArray As String()
        Dim hour As Integer = 0
        Dim minute As Integer = 0
        Dim second As Integer = 0


        If dateTimeArray.Length >= 2 Then

            If (dateTimeArray(0).ToString().Contains(":") = True) Then
                timeArray = dateTimeArray(0).Split(":")
            Else
                timeArray = dateTimeArray(1).Split(":")
            End If

            hour = timeArray(0)
            minute = timeArray(1)
            If timeArray.Length > 2 Then
                second = timeArray(2)
            Else
                second = "00"
            End If

        End If


        Dim timePMArray As String()
        If dateTimeArray.Length >= 3 Then
            timePMArray = dateTimeArray(2).Split(" ")
            If (timePMArray(0) = "ã" Or timePMArray(0) = "pm" Or timePMArray(0) = "PM") And hour <> 12 Then
                hour = hour + 12
            End If
            If (timePMArray(0) = "ã" Or timePMArray(0) = "am" Or timePMArray(0) = "AM") And hour = 12 Then
                hour = 0
            End If
        End If

        Return nYear.ToString & "-" & nMonth.ToString("00") & "-" & nDay.ToString("00") & " " & hour.ToString("00") & ":" & minute.ToString("00") & ":" & second.ToString("00") & ":000"
    End Function


    



End Class
